import React from "react";
import { getMatchItem } from "../utils/getMatchItem";
import { RouterContext } from "../context/RouterContext";
import {createBrowserHistory} from 'history'

const browserHistory = createBrowserHistory()
class BrowserRouter extends React.Component<any, any> {
  getRouterMatchItem(rules) {
    return getMatchItem(rules, location.pathname);
  }
  // push() {}
  // listen(callback) {
  //  const un =  browserHistory.listen(callback)
  //   return () => {
  //     un()
  //   };
  // }
  render() {
    return (
      <RouterContext.Provider
        value={{
          history:browserHistory,
          pathname:()=>location.pathname,
          // listen:this.listen.bind(this),
          getRouterMatchItem: this.getRouterMatchItem.bind(this),
          // push: this.push,
        }}
      >
        {this.props.children}
      </RouterContext.Provider>
    );
  }
}
export default BrowserRouter;
